package breeze.pixel.weather.apps_util.utils.appsettings;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.preference.PreferenceManager;

public class AppSettings extends SettingsStaticData {

	public static final String TAG = "AppSettings";

	public static AppSettings mAppSettings;

	public final SharedPreferences preference;

	public int getPatchVersion() {
		return preference.getInt("patchVersion", 0);
	}

	public void setPatchVersion(int patchVersion) {
		preference.edit().putInt("patchVersion", patchVersion).apply();
	}

	public AppSettings(Context context) {
		preference = PreferenceManager.getDefaultSharedPreferences(context);
	}

	public SharedPreferences getPreference(){
		return this.preference;
	}

	public void setBackgroundModeType(int backgroundModeType) {
		preference.edit().putInt("BackgroundModeType", backgroundModeType).apply();
	}

	public int getBackgroundModeType() {
		return preference.getInt("BackgroundModeType", TYPE_BACKGROUNDMODE_DEFAULT);
	}

	public void setDefaultKey(int key) {
		preference.edit().putInt("DefaultKey", key).apply();
	}

	public int getDefaultKey() {
		return preference.getInt("DefaultKey", 0);
	}

	public void setDefaultCityCode(String code) {
		preference.edit().putString("defaultCityCode", code).apply();
	}

	public String getDefaultCityCode() {
		return preference.getString("defaultCityCode", DEFAULT_CITY_CODE);
	}

	public void setDefaultCityName(String name) {
		preference.edit().putString("cityName", name).apply();
	}

	public boolean isHotFix() {
		return preference.getBoolean("hotFix",true);
	}

	public void setHotFix(boolean hotFix) {
		preference.edit().putBoolean("hotFix", hotFix).apply();
	}

	public boolean isFirstOpenApp(){
		return preference.getBoolean("isFirstOpenApp",true);
	}

	public void haveFirstOpenedApp(){
		preference.edit().putBoolean("isFirstOpenApp",false).apply();
	}

	public void setDonated(boolean bool){
		preference.edit().putBoolean("Donated",bool).apply();
	}

	public boolean isDonated(){
		return preference.getBoolean("Donated",false);
	}

	public String getDefaultCityName() {
		return preference.getString("cityName", "北京");
	}

	public static AppSettings getInstance(Context context) {
		if (mAppSettings == null) {
			mAppSettings = new AppSettings(context);
		}
		return mAppSettings;
	}

	public void setTaskCache(String tasks2) {
		preference.edit().putString("taskCache", tasks2).apply();
	}

	public String getTaskCache() {
		return preference.getString("taskCache", "");
	}

	public boolean getPanelTheme() {
		return preference.getBoolean("panelTheme", false);
	}

	public void setPanelTheme(boolean a) {
		preference.edit().putBoolean("panelTheme", a).apply();
	}

	public int getTextFont() {
		return preference.getInt("textFont", 1);
	}

	public void setTextFont(int i) {
		preference.edit().putInt("textFont", i).apply();
	}

	public void setTextSize(int size) {
		preference.edit().putInt("textSize", size).apply();
	}

	public int getTextSize() {
		return preference.getInt("textSize", 15);
	}

	public void setAutoGetLocation(boolean bool) {
		preference.edit().putBoolean("AutoGetLocation", bool).apply();
	}

	public boolean isAutoGetLocation() {
		return preference.getBoolean("AutoGetLocation", true);
	}

	public void setCheckNewVersion(boolean bool) {
		preference.edit().putBoolean("CheckNewVersion", bool).apply();
	}

	public boolean getCheckNewVersion() {
		return preference.getBoolean("CheckNewVersion", true);
	}

	public void setIgnoreVersion(int versionCode) {
		preference.edit().putInt("IgnoreVersion", versionCode).apply();
	}

	public int getIgnoreVersion() {
		return preference.getInt("IgnoreVersion", 0);
	}

	@Deprecated
	public void setBrightness(int brightness) {
		preference.edit().putInt("Brightness", brightness).apply();
	}

	@Deprecated
	public int getBrightness() {
		return preference.getInt("Brightness", -70);
	}

	@Deprecated
	public void setAppWidgetAlpha(int alpha) {
		preference.edit().putInt("AppWidgetAlpha", alpha).apply();
	}

	@Deprecated
	public int getAppWidgetAlpha() {
		return preference.getInt("AppWidgetAlpha", 255);
	}

	@Deprecated
	public void setAppwidgetTextColor(int textColor) {
		preference.edit().putInt("AppwidgetTextColor", textColor).apply();
	}

	@Deprecated
	public int getAppwidgetTextColor() {
		return preference.getInt("AppwidgetTextColor", Color.BLACK);
	}

	public void setAnnouncement(String announcement) {
		preference.edit().putString("Announcement", announcement).apply();
	}

	public String getAnnouncement() {
		return preference.getString("Announcement", "");
	}

	public void setIconType(int type) {
		preference.edit().putInt("IconType", type).apply();
	}

	public int getIconType() {
		return preference.getInt("IconType", 2);
	}

	public void setIsUsingSpeak(boolean b) {
		preference.edit().putBoolean("IsUsingSpeak", b).apply();
	}

	public boolean IsUsingSpeak() {
		return preference.getBoolean("IsUsingSpeak", false);
	}

	public void setSpeakSpeed(float f) {
		preference.edit().putFloat("SpeakSpeed", f).apply();
	}

	public float getSpeakSpeed(){
		return preference.getFloat("SpeakSpeed", 1.0f);
	}

	public void setSpeakPitch(float f) {
		preference.edit().putFloat("SpeakPitch", f).apply();
	}

	public float getSpeakPitch(){
		return preference.getFloat("SpeakPitch", 1.0f);
	}

	public void setSpeakContent(String content){
		preference.edit().putString("SpeakContent",content).apply();
	}

	public boolean isHideExtraData(){
		return preference.getBoolean("settings_hide_extra_data", false);
	}

	public int getCardViewTransparency(){
		return preference.getInt("CardViewTransparency",200);
	}

	public void setCardViewTransparency(int value){
		preference.edit().putInt("CardViewTransparency",value).apply();
	}

	public int getCardViewRadius(){
		return preference.getInt("CardViewRadius",20);
	}

	public void setCardViewRadius(int value){
		preference.edit().putInt("CardViewRadius",value).apply();
	}

	public String getSpeakContent(){
		return preference.getString("SpeakContent", "");
	}

	public boolean isAutoSaveTaskInPanel() {
		return preference.getBoolean("auto_save_task", true);
	}
}
